package com.gaoyubo.controller;

import com.gaoyubo.entity.City;
import com.gaoyubo.entity.Ctype;
import com.gaoyubo.entity.SearchVO;
import com.gaoyubo.entity.VO;
import com.gaoyubo.service.CityService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.logging.Logger;

@RestController
/*@CrossOrigin*/
@RequestMapping("city")
public class CityController {
  @Autowired
  CityService cityService;
  @RequestMapping("list")
  public PageInfo pageInfo(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "3") Integer pageSize,
                           SearchVO searchVO){
    System.out.println(pageNum);
    System.out.println(pageSize);
    System.out.println("列表");
    System.out.println("searchVO:{"+searchVO);
    System.out.println(cityService.getList(pageNum,pageSize,searchVO));
    return cityService.getList(pageNum,pageSize,searchVO);
  }
  @RequestMapping("typeList")
  public List typeList(){
    return cityService.typeList();
  }
  @RequestMapping("deleteById")
  public boolean deleteById(Integer id){
    try {
      cityService.deleteById(id);
      return true;
    }catch (Exception e){
      return false;
    }

  }
  @RequestMapping("deleteByIds")
  public boolean deleteByIds(String ids){
    try {
      System.out.println(ids);
      cityService.deleteByIds(ids);
      return true;
    }catch (Exception e){
      return false;
    }

  }
  @RequestMapping("saveOrUpdate")
  public boolean saveOrUpdate(@RequestBody VO vo){
    try {
      System.out.println(vo);
      cityService.saveOrUpdate(vo);
      return true;
    }catch (Exception e){
      return false;
    }

  }
  @RequestMapping("getListById")
  public City getListById(Integer id){
    return cityService.getListById(id);
  }
}
